#ifndef SERVERMESSAGEADAPTER_H
#define SERVERMESSAGEADAPTER_H

#include <QObject>
#include<QDebug>
#include <QThread>
#include<QPair>
#include<QList>
#include <QJsonArray>
#include<QJsonObject>
#include<QJsonDocument>
#include<QJsonParseError>
#include"Socket/TCPSocket.h"
#include"Socket/Package.h"
#include"Account/account.h"
#include<QDebug>
#include<QTimer>
class ServerMessageAdapter : public QObject
{
    //调度所有与服务器相关的信息处理和反馈
    Q_OBJECT
public:
    static ServerMessageAdapter* getInstance()
    {
        if(server_msg_adapter==nullptr)
            server_msg_adapter =new ServerMessageAdapter();
        return server_msg_adapter;
    }
    void setSocket(TCPSocket* socket);

signals:
  void resultReady(const QString &str); // 向外界发送结果
  void sig_REIGSTER_RES(QString uid);
  void sig_LOGIN_SUCCESS(bool is_success);
  void sig_LOGIN_INFO(QString name,QString uid,QString passwd);
  void sig_MSG_SYNC(QString,QList<QPair<QString,QString>>);
  void sig_LIST_SYNC();
  void sig_MSG_ACC(QString,QString);
  void sig_MSG_ACC(QString gid,QString uid,QString msg);
  void sig_POST_SYNC();

private:
//    TCPSocket* socket;
  explicit ServerMessageAdapter(QObject *parent = nullptr);
  static ServerMessageAdapter* server_msg_adapter;
  int getServerMessage();

  void msgToJson(const QJsonObject& obj);
public slots:
  void run(); // 耗时操作
  void solveServerMessage();
  //upLoad
  void sendMessage(Package::LoginRequestSend);
  void sendMessage(Package::RegisterRequestSend);
  void sendMessage(Package::AddAssociationSend);
  void sendMessage(Package::ChecknumRequestSend);
  void sendMessage(Package::MessageSend);
  void sendInfoSyncMessage();
  void sendMessage(Package::InfoSyncRequestSend);
  void sendMessage(Package::MessageHistoryRequestSend);
  void sendMessage(Package::AddFriendRequestSend);
  void sendMessage(Package::AgreeToGroupStatus);
  void sendMessage(Package::AgreeToAddFriendStatus);
  void sendMessage(Package::CreateGroup);


};

#endif // SERVERMESSAGEADAPTER_H
